
<?php
error_reporting(E_ALL); 
  require_once("OAuth.php");
  require("cert_file_accessor.php");
  
  class OrkutSignatureMethod extends OAuthSignatureMethod_RSA_SHA1 
  {
    protected function fetch_public_cert(&$request)
	{
		$cert_accessor = new CertFileAccessor('/certs', 'orkut');
		$cert = $cert_accessor->getPublicKey($_REQUEST['xoauth_signature_publickey']);
		return $cert;
    }
  }

  $request = OAuthRequest::from_request(null, null, array_merge($_GET, $_POST));
  $signature_method = new OrkutSignatureMethod();
  @$signature_valid = $signature_method->check_signature($request, null, null, $_GET["oauth_signature"]);

  if ($signature_valid == true) 
  {  // valid request
	   
	 require("connect.php");
	
	 if (isset($_REQUEST["user_id"])) $user_id = trim($_REQUEST["user_id"]) ;
	
	 
	 if ($user_id != "" )
	 {
		  $query = "select * from orkut_users where user_id = '" . $user_id . "'";
		  $result = mysql_query($query, $con);
		  
		  if (mysql_num_rows($result) != 0)
		  {
					$insert_query = "insert into orkut_activities(user_id,friend_id,ring_id) " ;
					$insert_query = $insert_query."values('" . $user_id . "','" . $friends_id . "'," . $ring_id . "')";
					mysql_query($insert_query, $con); 
		  }	
		  mysql_free_result($result) ;
	 }
	 else
	 { 	
		  echo("Invalid request!") ;
	 }
		
	 mysql_close($con) ;	
  } else {
    print "This request was spoofed";
  }

  //Add extra parameters to help debugging
 // $payload["query"] = array_merge($_GET, $_POST);
 // $payload["rawpost"] = file_get_contents("php://input");

  //Return the response as JSON
 // print(json_encode($payload));
  
  ?>
